#ifndef _X_DEF_H
#define _X_DEF_H
#include <iostream>
//type define
typedef unsigned char byte;
typedef uint8_t  uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;

typedef int8_t  int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;

typedef int EPOLL_FD;

#define MAX_EPOLL_EVENTS         10000
#define MAX_TCP_TASK_QUEUE_SIZE  10000
#define MAX_NET_THREAD_SIZE      1
#define MAX_EPOLL_WAIT_TIME      2100
#define MAX_EPOLL_THREAD_TIMEOUT 100 // 100ms 50ms 固定的tick时间
#define MAX_DATA_PACKAGE_SIZE    256*1024
#define MIN_DATA_PACKAGE_SIZE    6
#define DATA_PACKAGE_HEAD_SIZE   4
#define EPOLL_SIZE               2000
#define MAX_QUERY_LEN            2 * 1024 * 1024

//printf color
#define NONE         "\033[m"
#define RED          "\033[0;32;31m"
#define LIGHT_RED    "\033[1;31m"
#define GREEN        "\033[0;32;32m"
#define LIGHT_GREEN  "\033[1;32m"
#define BLUE         "\033[0;32;34m"
#define LIGHT_BLUE   "\033[1;34m"
#define DARY_GRAY    "\033[1;30m"
#define CYAN         "\033[0;36m"
#define LIGHT_CYAN   "\033[1;36m"
#define PURPLE       "\033[0;35m"
#define LIGHT_PURPLE "\033[1;35m"
#define BROWN        "\033[0;33m"
#define YELLOW       "\033[1;33m"
#define LIGHT_GRAY   "\033[0;37m"


#define MACRO_PROPERTY_DEF( T, varName, funName )					\
	protected: T varName;											\
	public: T Get##funName() const {return varName;}		\
	public: void Set##funName( T var ) {varName = var;}

#define MACRO_PROPERTY_READONLY( T, varName, funName )				\
	protected: T varName;											\
	public: T Get##funName() const {return varName;}

#define MACRO_PROPERTY_REF_DEF( T, varName, funName )				\
	protected: T varName;											\
	public: T& Get##funName() {return varName;}	\
	public: void Set##funName( const T& var ) { varName = var; }

#define MACRO_PROPERTY_REF_READONLY( T, varName, funName )				\
	protected: T varName;											\
	public: T& Get##funName() {return varName;}	

#define MACRO_PROPERTY_REF_CONST_DEF( T, varName, funName )			\
	protected: T varName;											\
	public: const T& Get##funName() {return varName;}		\
	public: void Set##funName( const T& var ) { varName = var; }

#define SAFE_SEND_DATAPACK(fd,PACK)                                      \
uint16 opcode = PACK.getOpcode();                                      \
uint32 pack_size = PACK.Size() + sizeof(uint16) + sizeof(uint32);  \
::send(fd,&pack_size,sizeof(uint32),0);                                \
::send(fd,&opcode,sizeof(uint16),0);                                   \
::send(fd,PACK.ReadBegin(),PACK.Size(),0);                                \
PACK.AddRPos(PACK.Size());

#define DEFINE_SYSTEM_BEGIN(NAME) \
class NAME{ \
protected: \
    NAME(){};\
    ~NAME(){};\
public: \
    void loadAllData();\
    void saveAllData();\
    void update();\
    bool InitSystem();\
public:\
    static NAME& GetSystem() {\
        static NAME instance;\
        return instance;\
    }

#define DEFINE_SYSTEM_END() \
};

#define RETURN_FALSE_IF_INIT_FAIL(SYS) \
if(!SYS::GetSystem().InitSystem())\
{\
    LogError("%s init fail",#SYS);\
    return false;\
}

#define DELETE(ENTRY) \
    if(ENTRY)\
    {\
        delete ENTRY; \
        ENTRY = nullptr;\
    }

#define CONSOLE_LOG_OUT 
     
#define NET_ENGINE_CORE_API
#endif